<?php
namespace app\modules\admin\components;

use yii\helpers\BaseArrayHelper;

class ArrayHelper extends BaseArrayHelper
{
	public static function itemsMerge(array $items, $pid = 0, $idField = "id", $pidField = 'pid')
    {
        $arr = [];
        foreach($items as $v)
        {
            if ($v[$pidField] == $pid)
            {
                $v['-'] = self::itemsMerge($items, $v[$idField], $idField, $pidField);
                $arr[] = $v;
            }
        }

        return $arr;
    }

    public static function itemsLevel($level, array $models, $k, $treeStat = 1)
    {
        $str = '';
        for ($i = 1; $i < $level; $i++)
        {
            $str .= '　　';
            if ($i == $level - $treeStat)
            {
                if (isset($models[$k + 1]))
                {
                    return $str . "├──";
                }

                return $str . "└──";
            }
        }

        return false;
    }
}